﻿using System.Collections;
using System.Collections.Generic;
using System.IO;
using System;
using UnityEngine;
using Cemit.NetFramework.Logger;

#if UNITY_EDITOR
using UnityEditor;
using Cemit.NetFramework.Editor;
#endif

namespace Cemit.NetFramework
{
    [CreateAssetMenu(menuName = "PolyNetwork/PolyServerSettings", fileName = "PolyServerSettings")]
    public class PolyServerSettings : ScriptableObject
    {
        [Header("地址设置")]
        public string ip = "127.0.0.1";
        public int port = 2333;

        [Header("调试设置")]
        public LoggerLevel logger = LoggerLevel.All;

        [Header("已弃用")]
        [Obsolete]
        public KeyCode[] netInputKey = new KeyCode[0];
        [Obsolete]
        public string[] netInputBotton;

        static string FileName => "PolyServerSettings";

#if UNITY_EDITOR
        static string FilePath => Path.Combine(PolyPath.Resources, FileName + ".asset");
#endif

#if UNITY_EDITOR
        [MenuItem("PolyNetwork/Create Server Settings")]
        public static PolyServerSettings CreateSettings()
        {
            if (File.Exists(FilePath))
            {
                Selection.activeObject = LoadSetting();
            }
            else
            {
                PolyPath.CreateAsset(
                    CreateInstance<PolyServerSettings>(), FilePath);
            }
            return LoadSetting();
        }

        private static PolyServerSettings LoadSetting()
        {
            if (!File.Exists(FilePath))
            {
                return null;
            }

            return PolyPath.LoadAsset<PolyServerSettings>(FilePath);
        }
#endif
    }
}